import React from 'react';
import { Modal } from 'antd';
import { IndexLink } from 'react-router'
import NavLink from './../menuBar/navLink'
let Header = React.createClass({
   contextTypes: {
     router: React.PropTypes.object
   },
   getInitialState() {
        return {
        visible: false
        }
    },

    logout() {
        this.setState({
        visible: true
        })
    },

    handleBack() {
        this.context.router.push('/');
    },

    handleOk() {
        Utils.sendAjax({
        url: '/funder/logout',
        callback: (result)=> {
            if (result.code == 200) {
            localStorage.funderUserName = '';
            localStorage.funderUserName = '';
            this.handleBack();
            this.handleCancel();
            }
        }
        })
    },

    handleCancel() {
        this.setState({
        visible: false
        })
    },
    render() {
        console.log(localStorage.funderUserName);
        return (
            <div>
                <div className="headerBg clearfix">
                    <div className="headerCon wrap1180 clearfix">
                        <div className="hearderLeft clearfix">
                            <div className="logo"></div>
                            <div className="nav">
                                <ul className="clearfix">
                                 
                                    <li><IndexLink to="/" activeClassName="active">首页</IndexLink></li>
                                    <li><NavLink to="/renter">我是租客</NavLink></li>
                                    <li><NavLink to="/landlord">我是房东</NavLink></li>
                                    <li><NavLink to="/suppliersService">供应链服务</NavLink></li>
                                    <li><NavLink to="/financialSupport">金融支持</NavLink></li>
                                    <li><NavLink to="/aboutUs">关于我们</NavLink></li>
                                </ul>
                            </div>
                        </div>
                        <div className="hearderRight">
                            <ul>
                                <li className="shequn">
                                    <i></i>
                                    <span><a href="#" target="_blank" className="loginBtn">爱租社群</a></span>
                                </li>
                                {
                                    localStorage.funderUserName?
                                    <li className="accountIcon">
                                        <i></i>
                                        <div className="accountNav">
                                            <dl>
                                                <dt></dt>
                                                <dd><NavLink to="/funder/resource/list">房源概览</NavLink></dd>
                                                <dd><NavLink to="/funder/accountSetting/index">账户设置</NavLink></dd>
                                                <dd><a href="javascript:;" onClick={this.logout}>退出账户</a></dd>
                                            </dl>
                                        </div>
                                    </li>:
                                    <li className="login">
                                        <i></i>
                                        <span><a href="#">登录</a></span>
                                    </li>    
                                }
                                
                            </ul>
                        </div>
                    </div>
                </div>
                <Modal title="退出" visible={this.state.visible} width={300}
                    onOk={this.handleOk} onCancel={this.handleCancel}>
                <p>是否退出当前用户？</p>
                </Modal>
            </div>
        )
    }
})

export default Header;